package tool

import (
	"github.com/gin-gonic/gin"
	"net/http"
)

const CookieName = "cookie_user"

const CookieExpire = 10 * 60

func CookieAuth(ctx *gin.Context) (*http.Cookie, error) {
	cookie, err := ctx.Request.Cookie(CookieName)
	if err != nil {
		// 没有获取到
		return nil, err
	}

	// 取到了cookie时,重新延长有效期
	ctx.SetCookie(CookieName, cookie.Value, cookie.MaxAge, cookie.Path, cookie.Domain, cookie.Secure, cookie.HttpOnly)
	return cookie, nil
}







